package com.factory.iamp.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Sap {
    private String order_id;
    private String AUART;
    private String WERKS;
    private String MATNR;
    private String GAMNG;
    private String GWEMG;
    private Timestamp GSTRP;
    private Timestamp GLTRP;
    private String KDAUF;
    private String KDPOS;
    private String KUNNR;

    public Sap(String xml) throws Throwable {
        Document document = DocumentHelper.parseText(xml);
        Element rtEle = document.getRootElement();
        this.order_id = rtEle.elementText("AUFNR");
        this.AUART = rtEle.elementText("AUART");
        this.WERKS = rtEle.elementText("WERKS");
        this.MATNR = rtEle.elementText("MATNR");
        this.GAMNG = rtEle.elementText("GAMNG");
        this.GWEMG = rtEle.elementText("GWEMG");
        this.GSTRP = Timestamp.valueOf(rtEle.elementText("GSTRP"));
        this.GLTRP = Timestamp.valueOf(rtEle.elementText("GLTRP"));
        this.KDAUF = rtEle.elementText("KDAUF");
        this.KDPOS = rtEle.elementText("KDPOS");
        this.KUNNR = rtEle.elementText("KUNNR");
    }

    public Sap(
            String AUFNR, String AUART, String WERKS, String MATNR, String GAMNG, String GWEMG, String GSTRP,
            String GLTRP, String KDAUF, String KDPOS, String KUNNR
    ) throws Throwable {
        this.order_id = AUFNR;
        this.AUART = AUART;
        this.WERKS = WERKS;
        this.MATNR = MATNR;
        this.GAMNG = GAMNG;
        this.GWEMG = GWEMG;
        this.GSTRP = Timestamp.valueOf(GSTRP);
        this.GLTRP = Timestamp.valueOf(GLTRP);
        this.KDAUF = KDAUF;
        this.KDPOS = KDPOS;
        this.KUNNR = KUNNR;
    }
}
